package cn.doit.scala.day04

/**
 * @DATE 2021/12/28/14:58
 * @Author MDK
 * @Version 2021.2.2
 * */
object C14_Take {
  def main(args: Array[String]): Unit = {
    val list: List[Int] = List[Int](1, 2, 3, 3, 4, 5, 1, 2, 2)
    //从头获取前三个元素
    val res: List[Int] = list.take(3)
    println(res)
    //从右往左获取3个元素
    val res2 = list.takeRight(3)
    println(res2)
    //当条件不满足时,不再获取元素
    val res3: List[Int] = list.takeWhile(_ < 4)
    println(res3)
  }

}
